<template>
	<view>
		<camera device-position="front" flash="off" @error="error" style="width: 100%; height: 80vh;"></camera>
		<view style="height: 20px;"> </view>
		<view class="photo" @click="takePhoto">
			拍照
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
			takePhoto() {
				let ctx = uni.createCameraContext()
				ctx.takePhoto({
					quality: 'normal',
					success: (res) => {
						uni.showToast({
							icon: 'none',
							title: '认证成功'
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
						uni.setStorageSync('face', true)
					},
					fail: (err) => {
						uni.showToast({
							title: '拍照失败，请检查系统是否授权',
							icon: 'none',
							duration: 1200
						})
					}
				})
			}
		}
	}
</script>

<style>
	.photo {
		width: 80px;
		height: 80px;
		background-color: #ff2c10;
		margin: 0 auto;
		border-radius: 50%;
		text-align: center;
		line-height: 80px;
		color: #fff;
		font-size: 22px;
	}
</style>
